home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / otohime / src / lib / fchan.asm < prev    next >
Assembly Source File  |  1994-06-01  |  8KB  |  372 lines

  1. ;            FREQENCY CHANGER
  2. ;
  3. ;        call from F-BASIC386 or High C
  4. ;    callm address,varptr(source),varptr(new),varptr(param),varptr(work)
  5. ;    void  FCHAN(*sourcesnd,*newsnd,*param,*work)
  6. ;
  7. ;
  8. ;            1990 3  Hiroshi TODA
  9. ;
  10. ;            1993 12 High C 用に改造
  11. ;
  12. ;    param: FreqencyExpandRate(mode)*10000H , MaxDataLength
  13. ;    work area = 256Byte
  14. ;
  15. ;
  16.  
  17.     .386p
  18.  
  19.  
  20. param    struc
  21.  
  22.     dd    ?
  23.     dd    ?
  24. source    dd    ?        ; source snd.data address
  25. new    dd    ?        ; new snd.data address
  26. paradd    dd    ?        ; param. address
  27. wadd    dd    ?         ; work address
  28.  
  29. param   ends
  30.  
  31. work    struc
  32.  
  33. ;data area
  34.  
  35. mode    dd    ?        ; rate
  36. max    dd    ?        ; max length
  37.  
  38. ;work area
  39.  
  40. point    dd    ?        ; ov.sampling point (decimal)
  41.     dd    ?        ; ov.sampling point (integer)
  42. rate    dd    ?        ; add (decimal)
  43.     dd    ?        ; add (integer)
  44. rend    dd    ?        ; read end
  45.  
  46. work    ends
  47.  
  48.  
  49. cseg    segment    dword public use32 'CODE'
  50.     assume    cs:cseg,ds:cseg
  51.  
  52.     public    sndPitch
  53.     db    'sndPitch',8
  54. sndPitch    proc    near
  55.     push    ebp
  56.     mov    ebp,esp
  57.     push    esi
  58.     push    edi
  59.     push    ebx
  60.  
  61.     mov    esi,[ebp].wadd        ; esi <-- work area top add
  62.     mov    ecx,[ebp].paradd    ; ecx <-- para. add.
  63.     xor    edx,edx            ; edx=count
  64. main01:    mov    eax,[ecx][edx*4]    ; para. --> work area
  65.     mov    [esi][edx*4],eax
  66.     inc    edx
  67.     cmp    edx,2
  68.     jb    main01
  69.     mov    eax,[esi].mode
  70.     cmp    eax,10H
  71.     ja    main0A
  72.     mov    eax,10H
  73.     mov    [esi].mode,eax    ; 1994 1 この行を追加,これがないとmode=0のとき多分暴走
  74.  
  75. main0A:    mov    ebx,[ebp].source    ; ebx <-- source snd. add.
  76.     mov    edi,[ebp].new        ; edi <-- new snd. add.
  77.     xor    edx,edx            ; head trans
  78. main02:    mov    eax,[ebx][edx*4]
  79.     mov    [edi][edx*4],eax
  80.     inc    edx
  81.     cmp    edx,8
  82.     jb    main02
  83.  
  84.     xor    ecx,ecx            ; ecx <-- counter
  85.     mov    eax,[ebx+12]
  86.     mov    [esi].rend,eax
  87.     cmp    eax,0
  88.     je    mainE
  89.     add    ebx,32            ; add head(32Byte)
  90.     add    edi,32
  91.     add    [esi].rend,ebx
  92.     sub    [esi].rend,1         ; endDataに等しいaddrを感知する必要があるため
  93.     mov    [esi].point+4,ebx    ; set integer
  94.     xor    edx,edx
  95.     mov    [esi].point,edx        ; decimal = 0
  96.     mov    eax,[esi].mode
  97.     shld    edx,eax,16
  98.     shl    eax,16
  99.     mov    [esi].rate,eax
  100.     mov    [esi].rate+4,edx
  101.     call    lp
  102.     cmp    ecx,2000H        ; data min length >=2000H
  103.     jae    main0C
  104.     cmp    [esi].max,0
  105.     je    main0C
  106.     mov    al,80H            ; make 0 data
  107. main0B:    mov    [edi],al
  108.     dec    dword ptr [esi].max
  109.     je    main0C
  110.     inc    ecx
  111.     inc    edi
  112.     cmp    ecx,2000H
  113.     jb    main0B
  114. main0C:    mov    edi,[ebp].new        ; edi <-- new snd. add.
  115.     mov    [edi+12],ecx        ; set length
  116.     xor    eax,eax            ; set loop point
  117.     mov    edx,01H
  118.     div    dword ptr [esi].mode
  119.     mul    dword ptr [edi+16]
  120.     shrd    eax,edx,16
  121.     cmp    eax,ecx
  122.     jb    main03
  123.     mov    eax,ecx
  124.     dec    eax
  125. main03:    mov    [edi+16],eax
  126.     xor    eax,eax            ; set loop length
  127.     mov    edx,01H
  128.     div    dword ptr [esi].mode
  129.     mul    dword ptr [edi+20]
  130.     shrd    eax,edx,16
  131.     mov    edx,eax
  132.     add    edx,[edi+16]
  133.     cmp    edx,ecx
  134.     jb    main04
  135.     mov    eax,ecx
  136.     sub    eax,[edi+16]
  137. main04:    mov    [edi+20],eax
  138. mainE:
  139.     pop    ebx
  140.     pop    edi
  141.     pop    esi
  142.     mov    esp,ebp
  143.     pop    ebp
  144.     ret
  145.  
  146. lp:    lea    eax,[esi].point
  147.     call    smp            ; ov.smp.
  148.  
  149.     mov    edx,[esi].point+4    ; 終了チェック
  150.     cmp    edx,[esi].rend
  151.     jb    lp01
  152.  
  153.     mov    eax,[esi].rend    ; データの終わりの例外処理
  154.     mov    al,[eax]
  155.     and    eax,0ffH
  156.     cmp    eax,128
  157.     jb    lp01
  158.     mov    edx,eax
  159.     mov    eax,128
  160.     sub    eax,edx
  161.  
  162. lp01:
  163.     call    wr            ; write
  164.     inc    ecx
  165.     dec    dword ptr [esi].max
  166.     je    lpE
  167.     call    adp
  168.  
  169.     mov    edx,[esi].point+4    ; 終了チェック
  170.     cmp    edx,[esi].rend
  171.     jbe    lp
  172.  
  173. lpE:    ret
  174.  
  175. ;    POINT=POINT+RATE
  176.  
  177. adp:    push    eax
  178.     push    edx
  179.     mov    eax,[esi].point
  180.     mov    edx,[esi].point+4
  181.     add    eax,[esi].rate
  182.     adc    edx,[esi].rate+4
  183.     mov    [esi].point,eax
  184.     mov    [esi].point+4,edx
  185.     pop    edx
  186.     pop    eax
  187.     ret
  188.  
  189. ;    WRITE DATA
  190. ;    eax -> pcm data -> [edi] & inc edi
  191.  
  192. wr:    cmp    eax,0            ; write
  193.     js    wr01
  194.     je    wr01
  195.     cmp    eax,128            ; +
  196.     jb    wr02
  197.     mov    eax,127
  198.     jmp    wr02
  199. wr01:    mov    edx,eax            ; -
  200.     mov    eax,128
  201.     sub    eax,edx
  202.     cmp    eax,256-1    ; data255はloopStopの意味があるから除外 1993 12
  203.     jb    wr02
  204.     mov    eax,255-1    ; data255はloopStopの意味があるから除外 1993 12
  205. wr02:    mov    [edi],al
  206.     inc    edi
  207.     ret
  208.  
  209. ;    OVER SAMPLING for PCM DATA(8bit)
  210. ;input    eax = 64bit(32bit/decimal,32bit/integer) data address(ds:)
  211. ;output    eax = over sampring data ( 32bit sign (-128 -- +127) )
  212.  
  213. smp:    push    ebx
  214.     push    ecx
  215.     push    edx
  216.     push    esi
  217.     push    edi
  218.     mov    ebx,[eax]        ; ebx = decimal
  219.     mov    esi,[eax+4]        ; esi = integer
  220.     shr    ebx,24            ; ebx --> 8bit
  221.     jne    smp00
  222.  
  223.     mov    al,[esi]        ; decimal=0
  224.     and    eax,0ffH
  225.     cmp    eax,128
  226.     jb    smp0A
  227.     mov    edx,eax
  228.     mov    eax,128
  229.     sub    eax,edx
  230. smp0A:    jmp    smp06
  231.  
  232. smp00:
  233.     mov    eax,[esi-1]        ; 周囲がみな無信号ならノイズを出さないよう直接0を返す
  234.     cmp    eax,80808080h
  235.     jne    smp0B
  236.     xor    eax,eax
  237.     jmp    smp06
  238.  
  239. smp0B:
  240.     call    smp01
  241. smp01:    pop    edi
  242.     add    edi,smptb-smp01        ; edi = table point
  243.  
  244.     mov    al,[esi]
  245.     and    eax,0ffH
  246.     cmp    eax,128
  247.     jb    smp02
  248.     mov    edx,eax
  249.     mov    eax,128
  250.     sub    eax,edx
  251. smp02:    add    eax,128
  252.     mul    byte ptr cs:[edi][ebx]
  253.     mov    ecx,eax
  254.  
  255.     mov    al,[esi-1]
  256.     and    eax,0ffH
  257.     cmp    eax,128
  258.     jb    smp03
  259.     mov    edx,eax
  260.     mov    eax,128
  261.     sub    eax,edx
  262. smp03:    add    eax,128
  263.     mul    byte ptr cs:[edi][ebx+256]
  264.     sub    ecx,eax
  265.  
  266.     mov    eax,ebx            ; ebx = 256 - ebx
  267.     mov    ebx,256
  268.     sub    ebx,eax
  269.  
  270.     mov    al,[esi+1]
  271.     and    eax,0ffH
  272.     cmp    eax,128
  273.     jb    smp04
  274.     mov    edx,eax
  275.     mov    eax,128
  276.     sub    eax,edx
  277. smp04:    add    eax,128
  278.     mul    byte ptr cs:[edi][ebx]
  279.     add    ecx,eax
  280.  
  281.     mov    al,[esi+2]
  282.     and    eax,0ffH
  283.     cmp    eax,128
  284.     jb    smp05
  285.     mov    edx,eax
  286.     mov    eax,128
  287.     sub    eax,edx
  288. smp05:    add    eax,128
  289.     mul    byte ptr cs:[edi][ebx+256]
  290.     sub    ecx,eax
  291.     sub    ecx,128*256
  292.     sar    ecx,8
  293.     mov    eax,ecx
  294.  
  295. smp06:    pop    edi
  296.     pop    esi
  297.     pop    edx
  298.     pop    ecx
  299.     pop    ebx
  300.     ret    
  301.  
  302. smptb    db    255,255,255,254,254,253,253,252
  303.     db    252,251,251,250,249,249,248,248
  304.     db    247,246,246,245,244,244,243,243
  305.     db    242,241,240,240,239,238,238,237
  306.     db    236,236,235,234,233,233,232,231
  307.     db    230,229,229,228,227,226,225,225
  308.     db    224,223,222,221,221,220,219,218
  309.     db    217,216,215,214,214,213,212,211
  310.     db    210,209,208,207,206,205,204,204
  311.     db    203,202,201,200,199,198,197,196
  312.     db    195,194,193,192,191,190,189,188
  313.     db    187,186,185,184,183,182,181,180
  314.     db    179,178,177,176,175,174,172,171
  315.     db    170,169,168,167,166,165,164,163
  316.     db    162,161,160,158,157,156,155,154
  317.     db    153,152,151,150,148,147,146,145
  318.     db    144,143,142,141,139,138,137,136
  319.     db    135,134,133,132,130,129,128,127
  320.     db    126,125,123,122,121,120,119,118
  321.     db    117,115,114,113,112,111,110,108
  322.     db    107,106,105,104,103,101,100,099
  323.     db    098,097,096,094,093,092,091,090
  324.     db    089,087,086,085,084,083,082,080
  325.     db    079,078,077,076,075,073,072,071
  326.     db    070,069,068,067,065,064,063,062
  327.     db    061,060,058,057,056,055,054,053
  328.     db    052,051,049,048,047,046,045,044
  329.     db    043,042,040,039,038,037,036,035
  330.     db    034,033,032,030,029,028,027,026
  331.     db    025,024,023,022,021,020,019,018
  332.     db    016,015,014,013,012,011,010,009
  333.     db    008,007,006,005,004,003,002,001
  334.  
  335.     db    000,000,001,001,001,002,002,002
  336.     db    003,003,003,003,004,004,004,005
  337.     db    005,005,005,006,006,006,006,007
  338.     db    007,007,007,008,008,008,008,009
  339.     db    009,009,009,009,010,010,010,010
  340.     db    010,011,011,011,011,011,011,012
  341.     db    012,012,012,012,012,013,013,013
  342.     db    013,013,013,013,014,014,014,014
  343.     db    014,014,014,014,014,015,015,015
  344.     db    015,015,015,015,015,015,015,015
  345.     db    015,016,016,016,016,016,016,016
  346.     db    016,016,016,016,016,016,016,016
  347.     db    016,016,016,016,016,016,016,016
  348.     db    016,016,016,016,016,016,016,016
  349.     db    016,016,016,016,016,016,016,016
  350.     db    016,016,016,016,016,016,016,016
  351.     db    016,016,016,016,016,016,016,016
  352.     db    016,016,015,015,015,015,015,015
  353.     db    015,015,015,015,015,015,015,015
  354.     db    014,014,014,014,014,014,014,014
  355.     db    014,014,014,013,013,013,013,013
  356.     db    013,013,013,013,012,012,012,012
  357.     db    012,012,012,012,012,011,011,011
  358.     db    011,011,011,011,011,010,010,010
  359.     db    010,010,010,010,009,009,009,009
  360.     db    009,009,009,008,008,008,008,008
  361.     db    008,008,007,007,007,007,007,007
  362.     db    007,006,006,006,006,006,006,005
  363.     db    005,005,005,005,005,004,004,004
  364.     db    004,004,004,003,003,003,003,003
  365.     db    003,002,002,002,002,002,002,001
  366.     db    001,001,001,001,001,000,000,000
  367.  
  368. sndPitch    endp
  369.  
  370. cseg    ends
  371.     end
  372.